var Login = function() {
	return {
		init : function() {
			$("#errorMsgDiv").hide();
			$('form.margin-bottom-0').validate(
					{
						rules : {
							loginName : {
								required : true
							},
							password : {
								required : true
							}
						},
						messages : {
							loginName : {
								required : messages.login_username_notempty
							},
							password : {
								required : messages.login_password_notempty
							}
						},
						submitHandler : function(form) {
							var postData = {};
							postData.loginName = $("#loginName").val();
							postData.password = $("#password").val();
							postData.rememberMe = $("#rememberMe").attr("checked") ? "1" : "0";
							var postUrl = ctx + "/login";
							$.ajax({
								"dataType" : 'json',
								"type" : "POST",
								"url" : postUrl,
								"data" : postData,
								"success" : function(result) {
									if (result.type == "success") {
										window.location.href = ctx + "/main.html";
									} else {
										// 错误信息展示
										$("#errorMsg").html(result.message);
										$("#errorMsgDiv").show();
									}
								}
							});
						}
					});
			/*
			 * $('form.margin-bottom-0 input').keypress(function(e) { if
			 * (e.which == 13) { $('form.margin-bottom-0').submit(); } });
			 */
		}

	};

}();